home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / HyperCard CTB Toolkit 1.0b2 / Source Code / CTBDispose.p < prev    next >
Encoding:
Text File  |  1995-02-07  |  4.5 KB  |  157 lines  |  [TEXT/MPS ]

  1. (*
  2.     CTBDispose [tool] -- Dispose of the tool indicated ("connection", "terminal", "file transfer"), closing
  3.         the connection if necessary. If tool is "all", then dispose of all tools.
  4.  
  5.     To compile and link this file using Macintosh Programmer's Workshop,
  6.  
  7.         pascal -w CTBDispose.p
  8.         link -m ENTRYPOINT -o HyperCommands -rt XCMD=2756 -sn Main=CTBDispose ∂
  9.             CTBClose.p.o "{MPW}"Libraries:interface.o "{MPW}"Libraries:Libraries:HyperXLib.o
  10.  
  11.     © Copyright 1990 by Apple Computer, Inc.
  12.  
  13.     Initial coding 2/90 by Harry R. Chesley.
  14. *)
  15.  
  16. {$R-}
  17.  
  18. {$S CTBDispose }     { Segment name must be the same as the command name. }
  19.  
  20. unit DummyUnit;
  21.  
  22. interface
  23.  
  24. uses MemTypes, QuickDraw, OSIntf, ToolIntf, CTBUtils, FTIntf, CMIntf, TMIntf, CRMIntf, HyperXCmd;
  25.  
  26. procedure EntryPoint(paramPtr: XCmdPtr);
  27.     
  28. implementation
  29.  
  30. procedure CTBDispose(paramPtr: XCmdPtr); forward;
  31.  
  32. procedure EntryPoint(paramPtr: XCmdPtr);
  33.  
  34.     begin
  35.         CTBDispose(paramPtr);
  36.     end;
  37.  
  38. procedure CTBDispose(paramPtr: XCmdPtr);
  39.  
  40.     {$I CTBUtil.inc}
  41.  
  42.     var i, j: integer;
  43.         tt: ToolType;
  44.         doToAll: boolean;
  45.         sizes: CMBufferSizes;
  46.         status: CMStatFlags;
  47.         err: CMErr;
  48.         cHand: ConnHandle;
  49.         theHand: ConnHandle;
  50.         theBuf: InputBufferHandle;
  51.         h: Handle;
  52.         gWind: WindowPtr;
  53.  
  54.     procedure Fail(errMsg: Str255); { set theResult and quit }
  55.         begin
  56.             paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
  57.             exit(CTBDispose);
  58.         end;
  59.  
  60.     begin
  61.         { Check the parameter count. }
  62.         if paramPtr^.paramCount > 1 then Fail('Invalid parameter count');
  63.  
  64.         { Check that the Comm Toolbox is present. }
  65.         CTBReady;
  66.  
  67.         { Figure out what to dispose of. }
  68.         if not ParmPresent(1) then doToAll := true
  69.         else if (Chr(paramPtr^.params[1]^^) = 'a') or (Chr(paramPtr^.params[1]^^) = 'A') then doToAll := true
  70.         else doToAll := false;
  71.  
  72.         { All tools or just one? }
  73.         if doToAll then
  74.             begin
  75.                 { Dispose of everything in the outstanding tool list. }
  76.                 for i := 1 to Globals^^.allToolsSize do
  77.                     case Globals^^.allTools[i].tType of
  78.                         connectionTool:
  79.                             begin
  80.                                 cHand := Globals^^.allTools[i].cHand;
  81.                                 if CMStatus(cHand,sizes,status) <> noErr then
  82.                                     if Band(status,cmStatusOpen+cmStatusOpening) <> 0 then
  83.                                         err := CMClose(cHand,false,nil,3600,true);
  84.                                 theBuf := InputBufferHandle(CMGetUserData(cHand));
  85.                                 if theBuf^^.termString <> nil then DisposHandle(theBuf^^.termString);
  86.                                 DisposHandle(Handle(theBuf));
  87.                                 CMDispose(cHand);
  88.                             end;
  89.                         terminalTool:
  90.                             begin
  91.                                 h := Handle(TMGetUserData(Globals^^.allTools[i].tHand));
  92.                                 gWind := Globals^^.allTools[i].tHand^^.owner;
  93.                                 TMDispose(Globals^^.allTools[i].tHand);
  94.                                 CloseWindow(gWind);
  95.                                 DisposHandle(h);
  96.                             end;
  97.                         fileTransferTool: FTDispose(Globals^^.allTools[i].ftHand);
  98.                         end;
  99.                 DeallocateGlobals;
  100.             end
  101.         else
  102.             begin
  103.                 tt := GetToolTypeParm(1);
  104.                 theHand := nil;
  105.                 case tt of
  106.                     connectionTool:
  107.                         if Globals^^.connHand <> nil then
  108.                             begin
  109.                                 cHand := Globals^^.connHand;
  110.                                 if CMStatus(cHand,sizes,status) <> noErr then
  111.                                     if Band(status,cmStatusOpen+cmStatusOpening) <> 0 then
  112.                                         err := CMClose(cHand,false,nil,3600,true);
  113.                                 theBuf := InputBufferHandle(CMGetUserData(cHand));
  114.                                 if theBuf^^.termString <> nil then DisposHandle(theBuf^^.termString);
  115.                                 DisposHandle(Handle(theBuf));
  116.                                 CMDispose(cHand);
  117.                                 theHand := cHand;
  118.                                 Globals^^.connHand := nil;
  119.                             end;
  120.                     terminalTool:
  121.                         if Globals^^.termHand <> nil then
  122.                             begin
  123.                                 h := Handle(TMGetUserData(Globals^^.termHand));
  124.                                 gWind := Globals^^.termHand^^.owner;
  125.                                 TMDispose(Globals^^.termHand);
  126.                                 CloseWindow(gWind);
  127.                                 DisposHandle(h);
  128.                                 theHand := ConnHandle(Globals^^.termHand);
  129.                                 Globals^^.termHand := nil;
  130.                             end;
  131.                     fileTransferTool:
  132.                         if Globals^^.FTHand <> nil then
  133.                             begin
  134.                                 FTDispose(Globals^^.FTHand);
  135.                                 theHand := ConnHandle(Globals^^.FTHand);
  136.                                 Globals^^.FTHand := nil;
  137.                             end;
  138.                     end;
  139.                 { If we succeeded in disposing of something, take it out of the outstanding tool list too. }
  140.                 if theHand <> nil then
  141.                     begin
  142.                         j := 1;
  143.                         for i := 1 to Globals^^.allToolsSize do
  144.                             if Globals^^.allTools[i].cHand <> theHand then
  145.                                 begin
  146.                                     Globals^^.allTools[j] := Globals^^.allTools[i];
  147.                                     j := j+1;
  148.                                 end;
  149.                         Globals^^.allToolsSize := Globals^^.allToolsSize-1;
  150.                         SetHandleSize(Handle(Globals),sizeof(OurGlobalType)-sizeof(ToolArray)+
  151.                                                 Globals^^.allToolsSize*sizeof(OneToolType))
  152.                     end;
  153.             end;
  154.     end;
  155.  
  156. end.
  157.